package com.interview;

/**
 * ThisDemo.. this的使用 try catch 中的返回值
 *
 * @author Lizhong
 * @date 2019/6/27
 */
public class ThisDemo {
    public static void main(String[] args) {

        System.out.println(new B().getValue());
        System.out.println(method01());
        System.out.println(method02());

    }

    static class A {

        int value;

        public A(int value) {
            setValue(value);

        }

        public int getValue() {
            try {
                value++;
                return value;
            } catch (Exception e) {
                System.out.println(e.getMessage());
            } finally {
                this.setValue(value);
                System.out.println(value);
            }
            return value;
        }

        public void setValue(int value) {
            this.value = value;
        }
    }

    static class B extends A {
        public B() {
            super(5); // value =10
            // getValue     value=22 ssout（22）
            int value = getValue();     // return try的value=11
            setValue(value - 3);       // valuse =16
        }

        public void setValue(int value) {
            super.setValue(2 * value);
        }


    }

    /**
     * try catch finally return结果
     * @return
     */

    public static int method01() {
        int i = 5;
        try {
            i++;
            return i;
        } finally {
            i *= 2;
            System.out.println(i);
        }
    }    public static int method02() {
        int i = 5;
        try {
            i++;
            return i;
        } finally {
            i *= 2;
            System.out.println(i);
            return i;
        }
    }
}
